package com.catchu.pattern.creational.迭代器模式.b进阶.iterator;

import com.catchu.pattern.creational.迭代器模式.b进阶.aggregate.ListPayAggregate;

/**
 * 具体的迭代器对象
 */
public class ListPayIterator implements Iterator {

    /**
     * 持有List实现的聚合对象
     */
    private ListPayAggregate payAggregate;

    /**
     * 下标索引值
     */
    private int index = -1;

    public ListPayIterator(ListPayAggregate payAggregate) {
        this.payAggregate = payAggregate;
    }

    @Override
    public void first() {
        this.index = 0;
    }

    @Override
    public void next() {
        if(this.index<payAggregate.size()){
            index++;
        }
    }

    @Override
    public boolean isDone() {
        if(index==payAggregate.size()){
            return true;
        }
        return false;
    }

    @Override
    public Object currentItem() {
        return this.payAggregate.get(index);
    }
}
